
import { createRouter, createWebHashHistory } from 'vue-router'//解构路由
import { ElMessage } from 'element-plus'

const routes = [
  {
    path: '/',
    redirect: '/login'
  },
  //登录
  {
    path: '/login',
    name: 'Login',
    component: () => import('../pages/Login.vue')
  },
  //首页
  {
    path: '/home',
    name: 'Home',
    redirect: '/home/user/setuser',
    meta: { permission: true },
    component: () => import('../components/Home.vue'),
    children: [
      //用户管理
      {
        path: "user",
        name: "user",
        component: () => import('../components/Useradmin.vue'),
        children: [
          {
            path: "setuser",
            meta: {
              title: '用户设置'
            },
            component: () => import("../pages/User/Setuser.vue"),

          }, {
            path: "time",
            meta: {
              title: '学时排行'
            },
            component: () => import("../pages/User/Studyranking.vue")
          },
          {
            path: "usercard",
            name: 'usercard',
            meta: {
              title: '用户卡劵'
            },
            component: () => import("../pages/User/Usercardstock.vue")
          }, {
            path: "cardhistory",
            meta: {
              title: '打卡记录'
            },
            component: () => import("../pages/User/Punchingcard.vue")
          }
        ]
      },
      //区域座位管理
      {

        path: "aseaseat",
        name: "asea",
        component: () => import('../components/Areaseatadmin.vue'),
        children: [
          {
            path: "aseas",
            meta: {
              title: '区域管理'
            },
            component: () => import("../pages/Seat/Areaadmin.vue")
          },
          {
            path: "seatdetails",
            meta: {
              title: '座位详情'
            },
            component: () => import("../pages/Seat/Seatdetails.vue")
          },
          {
            path: "seatreservation",
            meta: {
              title: '座位预约情况'
            },
            component: () => import("../pages/Seat/Seatreservation.vue")
          },


        ]
      },
      //卡劵管理
      {
        path: "cardadmin",
        name: "buycard",
        component: () => import('../components/Buycardadmin.vue'),
        children: [
          {
            path: "cardstock",
            meta: {
              title: '卡劵售卖'
            },
            component: () => import("../pages/card/Buycardstock.vue")
          }, {
            path: "buyhistory",
            meta: {
              title: '用户购买记录'
            },
            component: () => import("../pages/card/Userbuyhistory.vue")
          }
        ]
      },
      //订单充值
      {
        path: "ordertop",
        name: "order",
        component: () => import('../components/Ordertop.vue'),
        children: [
          {
            path: "orderamdin",
            meta: {
              title: '订单管理'
            },
            component: () => import("../pages/pay/Orderadmin.vue")
          }, {
            path: "prepaidadmin",
            meta: {
              title: '充值管理'
            },
            component: () => import("../pages/pay/Prepaidadmin.vue")
          }, {
            path: "prepaidprice",
            meta: {
              title: '充值价格配置'
            },
            component: () => import("../pages/pay/Prepaidprice.vue")
          }
        ]
      },
      //其他
      {
        path: "elseadmin",
        name: "else",
        component: () => import('../components/Elseadmin.vue'),
        children: [
          {
            path: "appointmenttime",
            meta: {
              title: '预约时间配置'
            },
            component: () => import("../pages/other/Appointmenttime.vue")
          }, {
            path: "businestime",
            meta: {
              title: '营业时间配置'
            },
            component: () => import("../pages/other/Businestime.vue")
          },
          {
            path: "closingtime",
            meta: {
              title: '停业时间配置'
            },
            component: () => import("../pages/other/Closingtime.vue")
          }, {
            path: "forhowlong",
            meta: {
              title: '兑换时长管理'
            },
            component: () => import("../pages/other/Forhowlong.vue")
          },
          {
            path: "gateadmin",
            meta: {
              title: '大门管理'
            },
            component: () => import("../pages/other/Gateadmin.vue")
          }, {
            path: "homeslideadmin",
            meta: {
              title: '首页幻灯配置'
            },
            component: () => import("../pages/other/Homeslideadmin.vue")
          }, {
            path: "phoneadmin",
            meta: {
              title: '商家电话管理'
            },
            component: () => import("../pages/other/Phoneadmin.vue")
          }, {
            path: "codeadmin",
            meta: {
              title: '兑换码管理'
            },
            component: () => import("../pages/other/Redeemcode.vue")
          }
        ]
      }
    ]
  },
]

//配置路由
const router = createRouter({
  history: createWebHashHistory(),
  routes,
})
router.beforeEach((to, from, next) => {
  if (to.meta.permission) {
    if (sessionStorage.getItem("admin")) {
      next();
    } else {
      ElMessage({
        message: '请先登录',
        type: 'warning',
        center: true,
      })
      next("/login");
    }
  } else {
    next();
  }
});
export default router
